define(function(require,exports,module){
	var searchTemp=require("text!../template/search.html");
	module.exports=Nuui.View.extend({
		template:searchTemp,
		onRender:function(){
			var view=this;
			
		},
		onShow:function(){
			var view=this;
			var dic={'server':0,'activity':1,'expert':2,'enterprise':3};
			var active=App.storage.get('searchActiveCode');
			var activeTab=dic[active];
			$('.search-tab .item').eq(activeTab).addClass('active').siblings().removeClass('active');
			$('.search-content .item').eq(activeTab).addClass('active').siblings().removeClass('active');
			/*tab切换*/
			$('.search-tab').on('tap','.item',function(){
				var index=$(this).index();
				$(this).addClass('active').siblings().removeClass('active');
				$('.search-content .item').eq(index).addClass('active').siblings().removeClass('active');
			})
			/*添加历史记录*/
			view.$('.search-content .item .search').on('focus keydown',function(e){
				var oldVal=$(this).val();
				if(e.keyCode==13){
					$(this).trigger('blur');
					
				}
			});
			view.$('.search-content .item .search').on('blur',function(){
				console.log('blur');
				var searchWord=$(this).val();
				$(this).val('');
				if(searchWord){
					var record=$('<a class="record-item ">'+searchWord+'</a>');

					var recordList=$(this).closest('.item').find('.record-list');
					if(recordList.find('.record-item').length==0){
						recordList.empty();
					}
					recordList.append(record);
				}
				
				
			});
			view.$('.search-content .item .search-box i').on('tap',function(e){
				$('.search-content .item .search').trigger('blur');
				if(e.keyCode==13){
					$('.search-content .item .search').trigger('blur');
					
				}
			})
			/*历史记录清除*/
			view.$('.search-content .item .his-record .title i').on('tap',function(){
				var noRecord=$('<li class="no-record">暂无历史搜索</li>')
				$(this).closest('.his-record').find('.record-list').empty().append(noRecord);
			})
		}
	})
})
